package protocol.SZ_2021;

import java.util.HashMap;

public class Handle2021SZ06 implements IHandle2021SZ {
    @Override
    public String handle(SZ_2021Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x08:
                return handle0608(cmd);
            case 0x0A:
                return handle060A(cmd);
            default:
                return "深标:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle0608(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:区域报警上报指令");
        builder.append("\r\n");
        SZ_2021Utils.handle0200Base(cmd,builder);

        builder.append("区域/线路ID:"+cmd.readWord());
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"进区域报警");
        list.put(1,"出区域报警");
        list.put(2,"超速报警");
        list.put(3,"非法开门报警");
        list.put(4,"跨区营运");

        builder.append("报警类型:"+list.getOrDefault(cmd.readWord(),"未定义"));
        builder.append("\r\n");

        builder.append("限速:"+cmd.readWord());
        builder.append("\r\n");

        builder.append("状态:"+(cmd.readWord()==0?"开始":"结束"));
        builder.append("\r\n");

        return builder.toString();
    }


    private String handle060A(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:查询区域线路应答");
        builder.append("\r\n");
        builder.append("查询消息流水号:"+cmd.readWord());
        builder.append("\r\n");
        builder.append("查询总数:"+cmd.readWord());
        builder.append("\r\n");
        builder.append("起始数:"+cmd.readWord());
        builder.append("\r\n");

        int num = cmd.readInt();
        builder.append("区域总数:"+num);

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"圆形");
        list.put(1,"矩形");
        list.put(2,"多边形");
        list.put(3,"路线");

        for (int i = 0; i < num; i++) {

            builder.append("    区域类型:" + list.getOrDefault(cmd.readInt(),"未定义"));
            builder.append("\r\n");
            builder.append("    区域ID:" + cmd.readDWord());
            builder.append("\r\n");
        }
        return builder.toString();
    }
}
